#coding:utf-8

import urllib2
from dagou.Agent import Agent

class Suning(Agent):
    '''
   分析suning.com
    '''

    def __init__(self):
        '''
        
        '''
        Agent.__init__(self)
        self.agentId = 4
        self.baseUrl = "http://search.suning.com/emall/search.do?keyword="
        self.code = 'utf-8'
        self.site = '苏宁'
        self.ename = 'suning'
#         self.ItemInfo = {'all' : "//li[number(@class)>0]",
#                          'store' : None,
#                          'name' : ("div[1]/span[1]/a[1]", None),
#                          'price' : ("div[1]/p[1]/img[1]", 'src'),
#                          'link' : ("div[1]/span[1]/a[1]", 'href'),
#                          'carriage' : None,
#                          'volume' : ("div[1]/div[1]/p[1]/a[1]", None),
#                          'end': (('price', 'fun', 'self.img_to_text'),
#                                  ('price', 'fun', 'self.GetNumFromStr'),
#                                  ('carriage', 'fun', 'self.GetNumFromStr'),
#                                  ('volume', 'fun', 'self.GetNumFromStr')),
#                          'fliter' : "price < 0.5 * oldprice",
#                          }

    def GetSearchList(self):
        while True:
            pri,form = self.que.get(1)
            self.BeginProcForm(form)
            print "seraching ",form.name
            url = form.name
            url = self.baseUrl + url
            req = urllib2.Request(url)
            result = self.opener.open(req).read()
#             open('suning.html','w').write(result)
    #         url2 = "http://price.360buy.com/PromotionFlag.aspx?pid=931716,931710,917460,919670,917461,919669,933093,933094,934434,934438,910152,910751,910162,1025667505,910273,1026551881,1026433519,910154,1025667506,910158,928034,923970,1027169314,910155,910749,916512,923968,910270,1026909436,923967,1026551880,1026433520,923966,923977,910269,933249"
    #         req = urllib2.Request(url2)
    #         req.add_header("Referer",url)
    #         dd = self.opener.open(req).read()
    #         open('dd.html','w').write(dd)
            self.ParseResult(result, form, pri)
            self.EndProcForm(form)